package com.zhss.designpattern.proxy;

public class ProxyPatternDemoPractice {
    public static void main(String[] args) {
        Subject concreteSubjects = new ConcreteSubjects();
//		ProxySubject proxySubject = new ProxySubject(concreteSubjects);
        //如果要无感知使用，那么代理类和被代理类要实现同一个接口
        Subject proxySubject = new ProxySubject(concreteSubjects);
        proxySubject.run();
    }

    /**
     * 统一的接口
     */
    public interface Subject {
        void run();
    }


    /**
     * 被代理的对象和方法
     */
    public static class ConcreteSubjects implements Subject {
        public void run() {
            System.out.println("这是要调用的方法");
        }

        ;
    }

    /**
     * 代理的类
     */
    public static class ProxySubject implements Subject {
        private Subject subject;

        public ProxySubject(Subject subject) {
            this.subject = subject;
        }

        public void run() {
            System.out.println("代理前的操作");
            subject.run();
            System.out.println("代理后的操作");
        }
    }
}
